package com.example.b_308.myapplication.view.register;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import com.example.b_308.myapplication.R;
import com.example.b_308.myapplication.view.base.BaseFragment;

/**
 * Created by B-308 on 2017/11/30.
 */
public class RegisterFragment2 extends  BaseFragment implements View.OnClickListener{
    EditText et_register_new_password, et_register_real_password;
    Button btn_next2;

        public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.activity_register2, null);
            btn_next2 = (Button) view.findViewById(R.id.btn_next2);
            et_register_new_password = (EditText) view.findViewById(R.id.et_register_new_password);
            et_register_real_password = (EditText) view.findViewById(R.id.et_register_real_password);
            et_register_real_password.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                }

                @Override
                public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                    if(et_register_real_password.getText().toString().equals(et_register_new_password.getText().toString())){
                        btn_next2.setSelected(true);
                    }
                }

                @Override
                public void afterTextChanged(Editable editable) {

                }
            });
            view.findViewById(R.id.btn_next2).setOnClickListener(this);
            return view;
        }

    @Override
    public void onClick(View v) {
        if (et_register_new_password.getText().toString().isEmpty()){
            ((RegisterActivity) getActivity()).onFail("密码不能为空");
        }else  if (et_register_real_password.getText().toString().isEmpty()){
            ((RegisterActivity) getActivity()).onFail("确认密码不能为空");
        }else if (!et_register_real_password.getText().toString().equals(et_register_new_password.getText().toString())){
            ((RegisterActivity) getActivity()).onFail("两次输入密码不一致");
        }else {
            ((RegisterActivity) getActivity()).next(this);
        }
    }
    //            , et_register_password.getText().toString()
}
